<template>
    <div>
        <Form
            class="declare-form"
            ref="form"
            :model="form"
            :show-message="false"
            :rules="formRules"
            v-blur="blurEvent"
            v-focusJump="{
                onEnter: enterEvent,
                onLast: handleLastEnter,
                dynamic: true
            }"
        >
            <Row>
                <iCol class="form-label" span="3">项号</iCol>
                <iCol span="2">
                    <FormItem prop="goodsIndex" class="formInput">
                        <Input disabled v-model="form.goodsIndex"></Input>
                    </FormItem>
                </iCol>
                <iCol class="form-label" span="3">备案序号</iCol>
                <iCol span="2">
                    <FormItem
                        prop="contrItem"
                        class="formInput"
                        :error="tips.contrItem"
                    >
                        <Input
                            name="contrItem"
                            :disabled="disabled"
                            :maxlength="19"
                            v-model.trim="form.contrItem"
                            :title="tips.contrItem"
                        ></Input>
                    </FormItem>
                </iCol>
                <iCol class="form-label" span="3">商品编号</iCol>
                <iCol :span="3">
                    <FormItem
                        prop="codeTs"
                        class="formInput requireBG codeTs"
                        :error="tips.codeTs"
                    >
                        <Input
                            name="codeTs"
                            :disabled="disabled"
                            :maxlength="10"
                            :title="tips.codeTs"
                            v-model.trim="form.codeTs"
                            @on-enter="openGoodsModal"
                        ></Input>
                    </FormItem>
                </iCol>
                <iCol class="form-label" :span="3">商品名称</iCol>
                <iCol span="5">
                    <FormItem
                        prop="goodsName"
                        class="formInput requireBG goodsName"
                        :error="tips.goodsName"
                    >
                        <Input
                            name="goodsName"
                            :disabled="disabled"
                            :maxlength="255"
                            v-model.trim="form.goodsName"
                            :title="tips.goodsName"
                            @on-enter="handleGoodsEnter"
                        ></Input>
                    </FormItem>
                </iCol>
            </Row>
            <Row>
                <iCol class="form-label" span="3">规格型号</iCol>
                <iCol span="13">
                    <FormItem
                        prop="goodsModel"
                        class="formInput"
                        :error="tips.goodsModel"
                    >
                        <Input
                            name="goodsModel"
                            v-model="form.goodsModel"
                            :title="tips.goodsModel"
                            readonly
                            @click.native="openGoodsModel"
                        ></Input>
                    </FormItem>
                </iCol>
                <iCol class="form-label" span="3">检疫检验名称</iCol>
                <iCol span="4">
                    <FormItem prop="ciqName" class="formInput ciqName">
                        <Input disabled v-model="form.ciqName"></Input>
                    </FormItem>
                </iCol>
                <iCol class="border morecenter" span="1">
                    <!-- 检验检疫code -->
                    <Button
                        v-model="form.ciqCode"
                        class="morebtn"
                        type="primary"
                        @click="openCIQmodel"
                    >
                        <i class="icon iconfont icon-more"></i>
                    </Button>
                </iCol>
            </Row>
            <Row>
                <iCol class="form-label" span="3">成交数量</iCol>
                <iCol span="2">
                    <FormItem
                        prop="gqty"
                        class="formInput requireBG gqty"
                        :error="tips.gqty"
                    >
                        <Input
                            name="gqty"
                            :disabled="disabled"
                            :title="tips.gqty"
                            :maxlength="20"
                            v-model.trim="form.gqty"
                            @on-blur="handleChangeGqty"
                        ></Input>
                    </FormItem>
                </iCol>
                <iCol class="form-label" span="3">成交计量单位</iCol>
                <iCol span="2">
                    <FormItem
                        prop="gunit"
                        class="formInput requireBG"
                        :error="tips.gunit"
                    >
                        <RemoteSearch
                            name="gunit"
                            :disabled="disabled"
                            :title="tips.gunit"
                            v-model="form.gunit"
                            keyword
                            :list="unitList"
                            placement="top-start"
                            keywordFiled="dataName"
                            valueField="dataCode"
                            :labelFieldList="['dataCode', 'dataName']"
                            @on-get-name="
                                name => {
                                    form.gunitCHN = name;
                                }
                            "
                            @on-blur="setGoodsFirstQtyByGqty"
                        ></RemoteSearch>
                    </FormItem>
                </iCol>
                <iCol class="form-label" span="3">单价</iCol>
                <iCol span="2">
                    <FormItem
                        prop="declPrice"
                        class="formInput requireBG"
                        :error="tips.declPrice"
                    >
                        <Input
                            name="declPrice"
                            :disabled="disabled"
                            :maxlength="19"
                            :title="tips.declPrice"
                            v-model.trim="form.declPrice"
                            @on-blur="handleChangePrice"
                        ></Input>
                    </FormItem>
                </iCol>
                <iCol class="form-label" span="1">总价</iCol>
                <iCol span="3">
                    <FormItem
                        prop="declTotal"
                        class="formInput requireBG"
                        :error="tips.declTotal"
                    >
                        <Input
                            name="declTotal"
                            :disabled="disabled"
                            :title="tips.declTotal"
                            :maxlength="18"
                            v-model.trim="form.declTotal"
                            @on-blur="handleChangeTotal"
                        ></Input>
                    </FormItem>
                </iCol>
                <iCol class="form-label" span="2">币制</iCol>
                <iCol span="3">
                    <FormItem
                        prop="tradeCurr"
                        class="formInput requireBG"
                        :error="tips.tradeCurr"
                    >
                        <RemoteSearch
                            name="tradeCurr"
                            :disabled="disabled"
                            :title="tips.tradeCurr"
                            v-model="form.tradeCurr"
                            :dropdownWidth="200"
                            placement="top-start"
                            :list="currencyCodeList"
                            keywordFiled="dataName"
                            valueField="dataCode"
                            :labelFieldList="['dataCode', 'dataName']"
                            :secondLabels="['dataSecondType', 'dataThirdType']"
                            @on-get-name="
                                name => {
                                    form.tradeCurrCHN = name;
                                }
                            "
                        ></RemoteSearch>
                    </FormItem>
                </iCol>
            </Row>
            <Row>
                <iCol class="form-label" span="3">法定第一数量</iCol>
                <iCol span="2">
                    <FormItem
                        prop="firstQty"
                        class="formInput requireBG"
                        :error="tips.firstQty"
                    >
                        <Input
                            name="firstQty"
                            :disabled="disabled"
                            :maxlength="20"
                            :title="tips.firstQty"
                            v-model.trim="form.firstQty"
                            @on-blur="checkFirstGqty"
                        ></Input>
                    </FormItem>
                </iCol>
                <iCol class="form-label" span="3">法一单位</iCol>
                <iCol span="2">
                    <FormItem prop="firstUnit" class="formInput">
                        <RemoteSearch
                            disabled
                            v-model="form.firstUnit"
                            keyword
                            :list="unitList"
                            placement="top-start"
                            keywordFiled="dataName"
                            valueField="dataCode"
                            :labelFieldList="['dataCode', 'dataName']"
                        ></RemoteSearch>
                    </FormItem>
                </iCol>
                <iCol class="form-label" span="3">加工成品版本号</iCol>
                <iCol span="2">
                    <FormItem
                        prop="exgVersion"
                        class="formInput"
                        :error="tips.exgVersion"
                    >
                        <Input
                            name="exgVersion"
                            :disabled="disabled"
                            :maxlength="8"
                            :title="tips.exgVersion"
                            v-model.trim="form.exgVersion"
                        ></Input>
                    </FormItem>
                </iCol>
                <iCol class="form-label" span="1">货号</iCol>
                <iCol span="3">
                    <FormItem
                        prop="exgNo"
                        class="formInput"
                        :error="tips.exgNo"
                    >
                        <Input
                            name="exgNo"
                            :disabled="disabled"
                            :maxlength="30"
                            :title="tips.exgNo"
                            v-model.trim="form.exgNo"
                        ></Input>
                    </FormItem>
                </iCol>
                <iCol class="form-label" span="2">最终目的国</iCol>
                <iCol span="3">
                    <FormItem
                        prop="destinationCountry"
                        class="formInput requireBG"
                        :error="tips.destinationCountry"
                    >
                        <RemoteSearch
                            name="destinationCountry"
                            :disabled="disabled"
                            :title="tips.destinationCountry"
                            v-model="form.destinationCountry"
                            :keyword="form.destinationCountryCHN"
                            :list="countryRegionList"
                            placement="top-start"
                            keywordFiled="dataName"
                            valueField="dataCode"
                            :labelFieldList="['dataCode', 'dataName']"
                            :secondLabels="['dataSecondType', 'dataThirdType']"
                            @on-get-name="
                                name => {
                                    form.destinationCountryCHN = name;
                                }
                            "
                        ></RemoteSearch>
                    </FormItem>
                </iCol>
            </Row>
            <Row>
                <iCol class="form-label" span="3">法定第二数量</iCol>
                <iCol span="2">
                    <FormItem
                        prop="secondQty"
                        class="formInput"
                        :class="{ requireBG: form.secondUnit }"
                        :error="tips.secondQty"
                    >
                        <Input
                            name="secondQty"
                            :disabled="disabled || !form.secondUnit"
                            :maxlength="20"
                            :title="tips.secondQty"
                            v-model.trim="form.secondQty"
                            @on-blur="checkSecondGqty"
                        ></Input>
                    </FormItem>
                </iCol>
                <iCol class="form-label" span="3">法二单位</iCol>
                <iCol span="2">
                    <FormItem prop="secondUnit" class="formInput">
                        <RemoteSearch
                            name="secondUnit"
                            disabled
                            v-model="form.secondUnit"
                            keyword
                            :list="unitList"
                            placement="top-start"
                            keywordFiled="dataName"
                            valueField="dataCode"
                            :labelFieldList="['dataCode', 'dataName']"
                        ></RemoteSearch>
                    </FormItem>
                </iCol>
                <iCol class="form-label" span="3">原产国</iCol>
                <iCol :span="isImport ? 3 : 11">
                    <FormItem
                        prop="originCountry"
                        class="formInput requireBG"
                        :error="tips.originCountry"
                    >
                        <RemoteSearch
                            name="originCountry"
                            :disabled="disabled"
                            :title="tips.originCountry"
                            v-model="form.originCountry"
                            :keyword="form.originCountryCHN"
                            :list="countryRegionList"
                            placement="top-start"
                            keywordFiled="dataName"
                            valueField="dataCode"
                            :labelFieldList="['dataCode', 'dataName']"
                            :secondLabels="['dataSecondType', 'dataThirdType']"
                            @on-get-name="
                                name => {
                                    form.originCountryCHN = name;
                                }
                            "
                        ></RemoteSearch>
                    </FormItem>
                </iCol>
                <!-- 进口展示 -->
                <template v-if="isImport">
                    <iCol class="form-label" span="3">原产地区</iCol>
                    <iCol span="5">
                        <FormItem
                            prop="origPlaceCode"
                            class="formInput"
                            :error="tips.origPlaceCode"
                        >
                            <RemoteSearch
                                name="origPlaceCode"
                                :disabled="disabled"
                                :title="tips.origPlaceCode"
                                v-model="form.origPlaceCode"
                                :keyword="form.origPlaceCodeCHN"
                                :list="originAreaList"
                                placement="top-start"
                                keywordFiled="dataName"
                                valueField="dataCode"
                                :labelFieldList="['dataCode', 'dataName']"
                                @on-get-name="
                                    name => {
                                        form.origPlaceCodeCHN = name;
                                    }
                                "
                            >
                            </RemoteSearch>
                        </FormItem>
                    </iCol>
                </template>
            </Row>
            <Row>
                <iCol class="form-label" span="3">
                    <Button style="float:left;" class="morebtn" type="primary" @click="goodshow = !goodshow">
                        <i class="icon iconfont" :class="goodshow ? 'icon-xia' : 'icon-shang'"></i>
                    </Button>
                    <span>境内{{isImport ? '目的' : '货源'}}地</span>
                </iCol>
                <iCol span="7">
                    <FormItem
                        prop="districtCode"
                        class="formInput requireBG"
                        :error="tips.districtCode"
                    >
                        <RemoteSearch
                            name="districtCode"
                            :disabled="disabled"
                            :title="tips.districtCode"
                            v-model="form.districtCode"
                            :keyword="form.districtCodeCHN"
                            :list="districtCodeList"
                            placement="top-start"
                            keywordFiled="dataName"
                            valueField="dataCode"
                            :labelFieldList="['dataCode', 'dataName']"
                            @on-get-name="
                                name => {
                                    form.districtCodeCHN = name;
                                }
                            "
                        ></RemoteSearch>
                    </FormItem>
                </iCol>
                <iCol span="6">
                    <FormItem
                        prop="destCode"
                        class="formInput"
                        :error="tips.destCode"
                    >
                        <RemoteSearch
                            name="destCode"
                            :disabled="disabled"
                            :title="tips.destCode"
                            v-model="form.destCode"
                            :keyword="form.destCodeCHN"
                            :list="destCodeList"
                            placeholder="产地代码"
                            placement="top-start"
                            keywordFiled="dataName"
                            valueField="dataCode"
                            :labelFieldList="['dataCode', 'dataName']"
                            @on-get-name="
                                name => {
                                    form.destCodeCHN = name;
                                }
                            "
                        ></RemoteSearch>
                    </FormItem>
                </iCol>
                <iCol class="form-label" span="3">征免方式</iCol>
                <iCol span="5">
                    <FormItem
                        prop="dutyMode"
                        class="formInput requireBG"
                        :error="tips.dutyMode"
                    >
                        <RemoteSearch
                            name="dutyMode"
                            :disabled="disabled"
                            :title="tips.dutyMode"
                            v-model="form.dutyMode"
                            keyword
                            :list="dutyModeList"
                            placement="top-start"
                            keywordFiled="dataName"
                            valueField="dataCode"
                            :labelFieldList="['dataCode', 'dataName']"
                            @on-get-name="
                                name => {
                                    form.dutyModeCHN = name;
                                }
                            "
                            @on-enter="handleInvtNetWtEnter"
                        ></RemoteSearch>
                    </FormItem>
                </iCol>
            </Row>
            <div v-show="goodshow">
                <Row>
                    <iCol
                        class="form-label"
                        span="3"
                    >检验检疫货物规格</iCol>
                    <iCol span="16">
                        <FormItem prop="goodsSpec" class="formInput">
                            <Input disabled v-model="showGoodsSpec"></Input>
                        </FormItem>
                    </iCol>
                    <iCol
                        class="border"
                        span="1"
                        style="text-align: center;"
                    >
                        <Button
                            class="morebtn"
                            type="primary"
                            @click="openGoodsSpec"
                        >
                            <i class="icon iconfont icon-more"></i>
                        </Button>
                    </iCol>
                    <iCol span="4">
                        <Button
                            type="primary"
                            @click="openGoodsApttr"
                        >产品资质</Button>
                    </iCol>
                </Row>
                <Row>
                    <iCol class="form-label" span="3">货物属性</iCol>
                    <iCol span="7">
                        <FormItem prop="goodsAttrCHN" class="formInput">
                            <Input
                                disabled
                                v-model="form.goodsAttrCHN"
                            ></Input>
                        </FormItem>
                    </iCol>
                    <iCol class="border morecenter" span="1">
                        <Button
                            class="morebtn"
                            type="primary"
                            @click="openGoodsAttr"
                        >
                            <i class="icon iconfont icon-more"></i>
                        </Button>
                    </iCol>
                    <iCol class="form-label" span="2">用途</iCol>
                    <iCol span="7">
                        <FormItem
                            prop="purpose"
                            class="formInput requireBG"
                            :error="tips.purpose"
                        >
                            <RemoteSearch
                                name="purpose"
                                :disabled="disabled"
                                :title="tips.purpose"
                                v-model="form.purpose"
                                keyword
                                :list="useCodeList"
                                placement="top-start"
                                keywordFiled="dataName"
                                valueField="dataCode"
                                :labelFieldList="['dataCode', 'dataName']"
                            ></RemoteSearch>
                        </FormItem>
                    </iCol>
                    <iCol span="4">
                        <Button
                            type="primary"
                            @click="openDangerInfo"
                        >危险货物信息</Button>
                    </iCol>
                </Row>
            </div>
        </Form>

        <!-- 获取商品列表 -->
        <div v-if="modalParams.goodsInfoShow">
            <goodsInfoModal
                v-model="modalParams.goodsInfoShow"
                @saveCustId="saveSelectGoods"
                :goodsInfo="modalParams.goodsInfoParams"
            />
        </div>
        <!-- 检疫检验列表弹框 -->
        <div v-if="modalParams.CIQModelShow">
            <CIQModel
                @saveCiq="saveCIQ"
                v-model="modalParams.CIQModelShow"
                :CIQModelParams="modalParams.CIQModelParams"
            />
        </div>
        <!-- 检验检疫货物规格 -->
        <div v-if="modalParams.CIQgoodsSpecShow">
            <CIQgoodsSpecModal
                v-model="modalParams.CIQgoodsSpecShow"
                @saveGoodsSpec="saveGoodsSpec"
                :CIQgoodsSpec="modalParams.CIQgoodsSpecParams"
            />
        </div>
        <!-- 货物属性 -->
        <div v-if="modalParams.goodsAttributeShow">
            <goodsAttributeModal
                v-model="modalParams.goodsAttributeShow"
                @saveGoodsAttribute="saveGoodsAttr"
                :goodsAttribute="modalParams.goodsAttributeParams"
            />
        </div>
        <!-- 产品资质 -->
        <div v-if="modalParams.goodsAptitudeShow">
            <goodsAptitudeModal
                v-model="modalParams.goodsAptitudeShow"
                @saveGoodsAptitude="saveGoodsAptitude"
                :goodsAptitude="modalParams.goodsAptitudeParams"
            />
        </div>
        <!-- 危险货物信息 -->
        <div v-if="modalParams.dangerGoodsInfoShow">
            <dangerGoodsInfoModal
                v-model="modalParams.dangerGoodsInfoShow"
                @saveDangerData="saveDangerData"
                :dangerGoodsInfo="modalParams.dangerGoodsInfoParams"
            />
        </div>
        <!--获取申报要素-->
        <detailsModal ref="detailsModalRef" @saveDetail="goodsModelConfirm" />
    </div>
</template>
<script>
import RemoteSearch from '@/view/components/RemoteSearch'
import { formRules, formMethods } from '@/mixins/form/form'
import eventMixin from '@/mixins/form/event'
import modalMixin from './mixins/modal'

import { evenRound } from '@/libs/tools'

export default {
    mixins: [formRules, formMethods, eventMixin, modalMixin],
    props: {
        // 进口还是出口 (默认进口)
        isImport: {
            type: Boolean,
            default: true
        },
        // 是否禁用
        disabled: {
            type: Boolean,
            default: false
        },
        unitList: {
            type: Array,
            default: () => []
        },
        currencyCodeList: {
            type: Array,
            default: () => []
        },
        countryRegionList: {
            type: Array,
            default: () => []
        },
        districtCodeList: {
            type: Array,
            default: () => []
        },
        destCodeList: {
            type: Array,
            default: () => []
        },
        dutyModeList: {
            type: Array,
            default: () => []
        },
        useCodeList: {
            type: Array,
            default: () => []
        },
        originAreaList: {
            type: Array,
            default: () => []
        }
    },
    components: {
        RemoteSearch
    },
    data () {
        return {
            goodshow: false,
            form: {
                goodsIndex: '', // 项号,(插入、上下移动、复制用，须保证项号连贯)

                ciqCode: '', // 检验检疫编码,
                ciqName: '', // 检验检疫名称,
                codeTs: '', // 商品编码,
                contrItem: '', // 备案序号,
                dangName: '', // 危险货物名称,
                dangPackSpec: '', // 危包规格,
                dangPackType: '', //   // 危包类别
                declPrice: '', // 单价,
                declTotal: '', // 总价,
                declareGoodsId: '', // 报关单商品id,
                declareId: '', // 报关报检单id,
                destCode: '', // 目的地 / 产地代码, 如北京市,
                destCodeCHN: '',
                destinationCountry: '', // 国家(出口： 目的国， 进口： 原产国)， 如： 澳大利亚， 只传AUS,
                destinationCountryCHN: '',
                districtCode: '', // 境内目的地 / 境内货源地， 如深圳特区， 只传44031,
                districtCodeCHN: '',
                dutyMode: '', // 征免方式， 传数字代码,
                dutyModeCHN: '',
                exgNo: '', // 货号,
                exgVersion: '', // 加工成品版本号,
                firstQty: '', // 数量1,
                firstUnit: '', // 第一单位, 如： 个， 只传007,
                goodsAttr: '', // 货物属性代码， 如： 3 C目录， 传11,
                goodsAttrCHN: '',
                goodsModel: '', // 规格型号,
                goodsName: '', // 商品名称,
                goodsSpec: '', // 检验检疫货物规格,
                gqty: '', // 数量,
                gunit: '', // 单位， 如个， 传007,
                gunitCHN: '',
                noDangFlag: '', // 非危险化学品
                origPlaceCode: '', // 原产地， 如： 澳大利亚， 只传AUS,
                originCountry: '', // 出口： 原产国， 进口： 目的国， 如： 阿富汗， 只传AUS,
                originCountryCHN: '',
                purpose: '', // 用途代码， 如： 种用或繁殖， 只传11,
                secondQty: '', // 数量2,
                secondUnit: '', // 第二单位， 如： 台， 只传035,
                tradeCurr: '', // 币制， 如： 人民币， 只传CNY,
                tradeCurrCHN: '',
                unCode: '', // UN编码,
                // ***随附单证表
                customsGoodsLimitNewVos: []
            },
            tips: {
                contrItem: '',
                codeTs: '',
                goodsName: '',
                goodsModel: '',
                gqty: '',
                gunit: '',
                declPrice: '',
                declTotal: '',
                tradeCurr: '',
                firstQty: '',
                exgVersion: '',
                exgNo: '',
                destinationCountry: '',
                secondQty: '',
                originCountry: '',
                origPlaceCode: '',
                districtCode: '',
                destCode: '',
                dutyMode: '',
                gdsSpcfModelDesc: '',
                purpose: ''
            }
        }
    },
    computed: {
        showGoodsSpec () {
            const { goodsSpec } = this.form
            return goodsSpec && goodsSpec.replace(/;+/g, ';').replace(/;$/, '') || ''
        }
    },
    methods: {
        handleGoodsEnter (event) {
            event.stopPropagation()
            this.focusElement('gqty')
        },
        // 打开规格型号弹窗
        openGoodsModel () {
            this.openGsmModal({
                codeTs: this.form.codeTs,
                goodsModel: this.form.goodsModel,
                ieFlag: this.isImport ? 'I' : 'E', // E 表示出口||出境  I 表示进口||进境
                disabled: this.disabled
            })
        },
        // 保存选择的商品数据
        saveSelectGoods (resData) {
            if (resData.selectedData.codeTs) {
                if (resData.selectedData.codeTs != this.form.codeTs) {
                    this.form.goodsModel = ''
                }
                this.form.codeTs = resData.selectedData.codeTs
                this.form.firstUnit = resData.selectedData.firstUnit
                this.form.secondUnit = resData.selectedData.secondUnit
                // 设置法一数量
                this.setGoodsFirstQtyByGqty()
                // 打开 获取申报要素 弹窗， 调用申报要素的接口
                this.openGoodsModel()
                // 清空校验
                this.tips.codeTs = ''
                this.tips.secondQty = ''
            } else {
                this.$Message.warning('请选择有效商品')
            }
        },
        // 保存商品规格
        goodsModelConfirm (v) {
            this.form.goodsModel = v
            this.focusElement('goodsName')
            this.tips.goodsModel = ''
            this.tips.goodsName = ''
        },

        /**
         * 处理商品表单区域 总价、单价、数量关联修改
         * 保留小数位： 总 2  单 4  数 5
         */
        // 处理总价改变
        handleChangeTotal () {
            const total = Number(this.form.declTotal) || 0
            const price = Number(this.form.declPrice) || 0
            const gqty = Number(this.form.gqty) || 0
            if (!total) return
            if (gqty) {
                // 如果有数量 则计算单价
                this.form.declPrice = evenRound(total / gqty, 4)
            } else if (price) {
                // 如果没有数据 有单价   则计算数量
                this.form.gqty = evenRound(total / price, 5)
            }
        },
        // 处理数量改变
        handleChangeGqty () {
            const total = Number(this.form.declTotal) || 0
            const price = Number(this.form.declPrice) || 0
            const gqty = Number(this.form.gqty) || 0
            if (!gqty) return
            if (price) {
                // 如果有单价  则计算总价
                this.form.declTotal = evenRound(gqty * price, 2)
            } else if (total) {
                // 如果没有单价 有总价   则计算单价
                this.form.declPrice = evenRound(total / gqty, 4)
            }
            this.setGoodsFirstQtyByGqty()
        },
        // 处理单价改变
        handleChangePrice () {
            const total = Number(this.form.declTotal) || 0
            const price = Number(this.form.declPrice) || 0
            const gqty = Number(this.form.gqty) || 0
            if (!price) return
            if (gqty) {
                // 如果有数量  则计算总价
                this.form.declTotal = evenRound(price * gqty, 2)
            } else if (total) {
                // 如果没有数量 有总价   则计算数量
                this.form.gqty = evenRound(total / price, 5)
            }
        },
        // 根据成交单位和法一单位是否相等设置 法一数据的值为 成交数量的值
        setGoodsFirstQtyByGqty () {
            const { firstUnit, gunit, gqty, secondUnit } = this.form
            if (firstUnit && firstUnit === gunit) {
                this.form.firstQty = gqty || ''
            }
            // 若成交单位与法二单位一致，则法二数量栏自动取成交数量栏里面的值。(TAPD_BUG:ID1021766)
            if (secondUnit && secondUnit === gunit) {
                this.form.secondQty = gqty || ''
            }
        },
        // 法二数量修改时判断 成交单位和法二单位是否一致 一致则同步成交数量 (TAPD_BUG:ID1021766)
        checkSecondGqty () {
            const { gunit, secondQty, secondUnit } = this.form
            if (secondUnit && secondUnit === gunit && Number(secondQty)) {
                this.form.gqty = secondQty
            }
        },
        // 法一数量修改时判断 成交单位和法一单位是否一致 一致则同步成交数量 (TAPD_BUG:ID1021766)
        checkFirstGqty () {
            const { gunit, firstQty, firstUnit } = this.form
            if (firstUnit && firstUnit === gunit && Number(firstQty)) {
                this.form.gqty = firstQty
            }
        },

        openGoodsApttr () {
            if (!(this.form.codeTs && this.form.goodsName)) {
                this.$Message.warning('商品编号和商品名称不能为空！')
                return false
            }
            const { codeTs, goodsName, ciqName, contrItem } = this.form
            // fix:模板配置中产品资质无法单独设置的bug(1022129)
            let customsGoodsLimitNewVos = Array.isArray(this.form.customsGoodsLimitNewVos) ? this.form.customsGoodsLimitNewVos.slice() : []
            // 判断是否模板配置中的数据 模板配置中的数据没有 codeTs goodsName ciqName contrItem
            if (
                customsGoodsLimitNewVos.length &&
                !customsGoodsLimitNewVos[0].codeTs
            ) {
                customsGoodsLimitNewVos.forEach(item => {
                    item.codeTs = codeTs
                    item.goodsName = goodsName
                    item.ciqName = ciqName
                    item.contrItem = contrItem
                })
                this.form.customsGoodsLimitNewVos = customsGoodsLimitNewVos
            }
            this.openGoodsAptitude({
                CustomsDeclareGoodsNewDate: {
                    codeTs,
                    goodsName,
                    ciqName,
                    contrItem,
                    customsGoodsLimitNewVos: JSON.parse(
                        JSON.stringify(customsGoodsLimitNewVos)
                    ),
                    declareGoodsId: this.form.declareGoodsId
                },
                editORshow: this.disabled,
                type: this.isImport ? 'jk' : 'ck'
            })
        },
        handleInvtNetWtEnter (event) {
            if (!this.goodshow) {
                event.stopPropagation()
                event.target.blur()
                if (this.enterEvent && this.enterEvent(event) === false) return
                this.handleLastEnter()
            }
        }
    }
}
</script>
